package cl.rizepe.playntest.core.views;



public class LayerPropertyAnimation {
	LayerProperties start,end;	
	
	float stepAlpha;
	float stepBackgroundColor;
	float stepPivotX,stepPivotY;
	float stepRotation;
	float stepScaleX, stepScaleY;
	float stepTranslateX, stepTranslateY;
	float stepX, stepY;
	
	
	long time=0;
	EffectedLayer layerState;
	boolean animating=false;
	double dt=0;
	boolean loop=false;
	public boolean isLoop() {
		return loop;
	}

	public void setLoop(boolean loop) {
		this.loop = loop;
	}

	public boolean isKeep() {
		return keep;
	}

	public void setKeep(boolean keep) {
		this.keep = keep;
	}


	boolean keep=true;
	
	public LayerPropertyAnimation(EffectedLayer layerState, long time){
		this.layerState=layerState;
		this.time=time*1000;		
	//	view.setAnimation(this);
		start =new LayerProperties(layerState);
		end =new LayerProperties(layerState);
	}

	public void updateSteps(){
		/*esto me dará mi variación por unidad de tiempo (mili segundo)
		 * */
		stepTranslateX=(end.translate.x()-start.translate.x())/time;
		stepTranslateY=(end.translate.y()-start.translate.y())/time;
	}
	
	boolean isAnimating(){
		return animating;
	}
	

	public void startAnimation(){
		updateSteps();
		dt=0;
		animating=true;
	}
	
	public void endAnimation(){
		
		animating=false;
		
		if (loop)
		{
			start.applyTo(layerState);
			startAnimation();
		}if (!keep){
			start.applyTo(layerState);
		}
	}
		
	public void setStart(LayerProperties start) {
		this.start = start;
	}
	public void setEnd(LayerProperties end) {
		this.end = end;
		updateSteps();
	}
	public LayerProperties getStart(){
		return start;
	}
	public LayerProperties getEnd(){
		return end;
	}
	
	
	public void update(double delta) {
			if (animating){
				dt += delta*1000;
				if (dt<=time){
					if (stepTranslateX!=0){
					float dx = (float) (start.translate.x()+stepTranslateX*dt);
					layerState.setTranslation(dx, layerState.getTranslate().y());
				}
			}else
					endAnimation();	
		}	
	}
}
